package com.educate.device.web.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.educate.common.web.R;
import com.educate.device.model.bo.DeviceStatusBO;
import com.educate.device.rpc.api.DeviceStatusService;
import lombok.extern.log4j.Log4j2;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Log4j2
@RestController
@RequestMapping("deviceStatus")
public class DeviceStatusController {

    @Reference(version = "${api.service.version}",
            application = "${dubbo.application.id}",
            url = "${dubbo.application.url}")
    private DeviceStatusService deviceStatusService;

    @PostMapping(value = "/create")
    public R create(@RequestBody DeviceStatusBO bo) {
        deviceStatusService.create(bo);
        return R.ok();
    }

    @PostMapping(value = "/delete")
    public R delete(@RequestBody DeviceStatusBO bo) {
        deviceStatusService.delete(bo);
        return R.ok();
    }

    @PostMapping(value = "/delete/{deviceStatusId}")
    public R delete(@PathVariable String deviceStatusId) {
        deviceStatusService.delete(deviceStatusId);
        return R.ok();
    }

    @PostMapping(value = "/detail/{deviceStatusId}")
    public R<DeviceStatusBO> detail(@PathVariable String deviceStatusId) {
        DeviceStatusBO bo = deviceStatusService.detail(deviceStatusId);
        return R.ok(bo);
    }

    @PostMapping(value = "/detail")
    public R<DeviceStatusBO> detail(@RequestBody DeviceStatusBO bo) {
        DeviceStatusBO detail = deviceStatusService.detail(bo);
        return R.ok(detail);
    }

    @PostMapping(value = "/update")
    public R<DeviceStatusBO> update(@RequestBody DeviceStatusBO bo) {
        deviceStatusService.update(bo);
        return R.ok();
    }

    @PostMapping(value = "/query")
    public R<Page<DeviceStatusBO>> query(@RequestBody DeviceStatusBO bo) {
        Page<DeviceStatusBO> result = deviceStatusService.query(bo, bo.pageable());
        return R.ok(result);
    }

    @PostMapping(value = "/list")
    public R<List<DeviceStatusBO>> list(@RequestBody DeviceStatusBO bo) {
        List<DeviceStatusBO> result = deviceStatusService.list(bo);
        return R.ok(result);
    }

}
